package main

import (
	"Library_Management_System/controller"
	"html/template"
	"net/http"
)

func main() {
	// 处理静态资源
	http.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("views/static"))))
	http.Handle("/pages/", http.StripPrefix("/pages/", http.FileServer(http.Dir("views/pages"))))

	// main页面
	http.HandleFunc("/main", func(w http.ResponseWriter, r *http.Request) {
		t := template.Must(template.ParseFiles("views/pages/login.html"))
		err := t.Execute(w, "")
		if err != nil {
			panic(err.Error())
		}
	})

	// 登录
	http.HandleFunc("/login", controller.Login)
	// 注册
	http.HandleFunc("/register", controller.Register)
	// 检查用户名是否重复
	http.HandleFunc("/checkUsername", controller.CheckUsername)
	// 转到用户信息页面
	http.HandleFunc("/getUserInfo", controller.GetUserInfo)
	// 转到用户图书借阅页面
	http.HandleFunc("/getUserBook", controller.GetUserBook)
	// 转到管理员图书管理页面
	http.HandleFunc("/getAdminBook", controller.GetAdminBook)
	// 转到管理员用户管理页面
	http.HandleFunc("/getAdminUser", controller.GetAdminUser)
	// 转到管理员图书借阅页面
	http.HandleFunc("/getAllBorrowInfo", controller.GetAllBorrowInfo)
	// 用户借阅功能
	http.HandleFunc("/updateBorrowInfo", controller.UpdateBorrowInfo)
	// 用户归还图书
	http.HandleFunc("/returnBook", controller.ReturnBook)
	// 根绝条件获取图书
	http.HandleFunc("/getBooksByCriteria", controller.GetBooksByCriteria)
	// 添加图书
	http.HandleFunc("/addBook", controller.AddBook)
	// 删除图书
	http.HandleFunc("/deleteBook", controller.DeleteBook)
	// 修改图书
	http.HandleFunc("/modifyBook", controller.ModifyBook)
	// 禁用用户
	http.HandleFunc("/disableUser", controller.DisableUser)
	err := http.ListenAndServe(":9090", nil)
	if err != nil {
		panic(err.Error())
	}
}
